package com.xintonghua.bussiness.util;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.Settings;
import android.widget.Toast;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class JumpUtils {

    public final static String SerializableKey = "data";

    // public final static int resultok = -1;
//
//	/**
//	 * 直接拨打拨打电话
//	 *
//	 * @param context
//	 * @param phoneNumber
//	 */
//	public static void Call(Context context, String phoneNumber) {
//		Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
//		// Intent intent = new
//		// Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+phoneNumber));
//		context.startActivity(intent);
//
//		// ((Activity) (context)).overridePendingTransition(R.anim.slide_left,
//		// R.anim.slide_right);
//
//	}

    /**
     * 只跳到拨打电话界面不打电话
     *
     * @param context
     * @param phoneNumber
     */
    public static void Call_DIAL(Context context, String phoneNumber) {
        // Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" +
        // phoneNumber));
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
        context.startActivity(intent);

        // ((Activity) (context)).overridePendingTransition(R.anim.slide_left,
        // R.anim.slide_right);

    }

    public static void jumpto(Context context, Class<?> classs, HashMap<String, String> map) {
        Intent intent = new Intent(context, classs);
        // intent.put
        System.out.println("通过Map.entrySet遍历key和value");
        // map.entrySet()
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }
        context.startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

    }

    /**
     * @param context
     * @param classs
     */
    public static void jumptoB(Context context, Class<?> classs, Bundle bun) {
        Intent intent = new Intent(context, classs);
        intent.putExtras(bun);
        context.startActivity(intent);
    }

    /**
     * @param context
     * @param classs
     * @param map
     * @param flag    flag
     */
    public static void jumpto(Context context, Class<?> classs, HashMap<String, String> map, int flag) {
        Intent intent = new Intent(context, classs);
        // intent.put
        intent.setFlags(flag);
        System.out.println("通过Map.entrySet遍历key和value");
        // map.entrySet()
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }
        context.startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

    }

    /**
     * @param context
     * @param classs
     * @param array   要传的数组
     * @param key     要传入的数组对应的key
     */
    public static void jumpto(Context context, Class<?> classs, String[] array, String key) {
        Intent intent = new Intent(context, classs);
        // intent.put
        System.out.println("通过Map.entrySet遍历key和value");
        // map.entrySet()

        intent.putExtra(key, array);

        context.startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

    }

    public static void jumpto(Context context, Class<?> classs, Serializable data, HashMap<String, String> map) {
        Intent intent = new Intent(context, classs);
        // intent.put

        intent.putExtra(SerializableKey, data);
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }

        context.startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

    }

    public static void jumpto(Context context, Class<?> classs, Serializable data) {
        Intent intent = new Intent(context, classs);
        // intent.put

        intent.putExtra(SerializableKey, data);
        context.startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

    }

    public static void jumptoP(Context context, Class<?> classs, Parcelable data) {
        Intent intent = new Intent(context, classs);
        // intent.put

        intent.putExtra(SerializableKey, data);
        context.startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
    }

//    public static void jumptoP(Context context, Class<?> classs, Parcelable data, HashMap<String, String> map) {
//        Intent intent = new Intent(context, classs);
//        // intent.put
//        intent.putExtra(SerializableKey, data);
//        if (map != null) {
//            for (Map.Entry<String, String> entry : map.entrySet()) {
//                intent.putExtra(entry.getKey(), entry.getValue());
//                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
//            }
//        }
//        context.startActivity(intent);
////		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
//
//    }

    public static void jumpto(Context context, Class<?> classs, Serializable data, boolean is_finish) {
        Intent intent = new Intent(context, classs);
        // intent.put

        intent.putExtra(SerializableKey, data);
        context.startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
        if (is_finish) {
            ((Activity) (context)).finish();
        }
    }

    public static Serializable getSerializable(Context context) {
        Serializable a = ((Activity) (context)).getIntent().getSerializableExtra(SerializableKey);
        return a;
    }
//
//    public static Parcelable getParcelable(Context context) {
//        Parcelable a = ((Activity) (context)).getIntent().getParcelableExtra(SerializableKey);
//        return a;
//    }

    public static Serializable getSerializable(Context context, String key) {
        Serializable a = ((Activity) (context)).getIntent().getSerializableExtra(key);
        return a;
    }

    public static String getString(Context context, String key) {
        String a = ((Activity) (context)).getIntent().getStringExtra(key);
        return a;
    }

    public static int getInteger(Context context, String key, int defaultkey) {
        int a = ((Activity) (context)).getIntent().getIntExtra(key, defaultkey);
        return a;
    }

    public static Double getDouble(Context context, String key, int defaultkey) {
        Double a = ((Activity) (context)).getIntent().getDoubleExtra(key, defaultkey);
        return a;
    }

    public static String[] getStringArray(Context context, String key) {
        String[] a = ((Activity) (context)).getIntent().getStringArrayExtra(key);
        return a;
    }

    public static boolean getBoolean(Context context, String key, boolean defaultValue) {
        boolean a = ((Activity) (context)).getIntent().getBooleanExtra(key, defaultValue);
        return a;
    }

    public static void jumpfinish(Context context) {
        ((Activity) (context)).finish();
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left2, R.anim.slide_right2);
    }

    /**
     * 功能同 startActivityForResult
     *
     * @param context
     * @param classs
     * @param map
     * @param requestCode
     */
    public static void jumpActivityForResult(Context context, Class<?> classs, HashMap<String, String> map, int requestCode) {
        Intent intent = new Intent(context, classs);
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }
        ((Activity) (context)).startActivityForResult(intent, requestCode);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
    }

    /**
     * 功能同 startActivityForResult
     *
     * @param context
     * @param classs
     * @param map
     * @param requestCode
     */
    public static void jumpActivityForResult(Context context, Class<?> classs, HashMap<String, String> map, int requestCode, boolean isOpenAnima) {
        Intent intent = new Intent(context, classs);
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }
        ((Activity) (context)).startActivityForResult(intent, requestCode);
//		if (isOpenAnima == true)
//			((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
    }

    /**
     * 功能同 startActivityForResult
     *
     * @param context
     * @param classs
     * @param serializable
     * @param requestCode
     */
    public static void jumpActivityForResult(Context context, Class<?> classs, Serializable serializable, int requestCode, boolean isOpenAnima) {
        Intent intent = new Intent(context, classs);
        //
        intent.putExtra(SerializableKey, serializable);
        ((Activity) (context)).startActivityForResult(intent, requestCode);
//		if (isOpenAnima == true)
//			((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
    }

    /**
     * 功能同 startActivityForResult
     *
     * @param context
     * @param classs
     * @param map
     * @param requestCode
     */
    public static void jumpActivityForResult(Context context, Class<?> classs, Serializable serializable, HashMap<String, String> map, int requestCode, boolean isOpenAnima) {
        Intent intent = new Intent(context, classs);
        // fff
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }
        intent.putExtra(SerializableKey, serializable);
        ((Activity) (context)).startActivityForResult(intent, requestCode);
//		if (isOpenAnima == true)
//			((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
    }

    /**
     * startActivityForResult 回传值
     *
     * @param context
     * @param Return_zhi 回传值
     * @param map        需要回传的数据
     */
    public static void jumpResultfinish(Context context, int Return_zhi, HashMap<String, String> map) {
        // 用 setResut()
        // 准备好要回传的数据后，只要使用finish()的方法就能把打包好的数据发给A且运行onActivityResult()部分的代码
        Intent intent = new Intent();
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }
        /* 将数据打包到aintent Bundle 的过程略 */
        ((Activity) (context)).setResult(Return_zhi, intent);// 这理有2个参数(int
        // resultCode,
        // Intent
        // intent)
        ((Activity) (context)).finish();
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left2, R.anim.slide_right2);
    }

    /**
     * startActivityForResult 回传值
     *
     * @param context
     * @param Return_zhi 回传值
     * @param map        需要回传的数据
     */
    public static void jumpResultfinish(Context context, int Return_zhi, Serializable serializable, HashMap<String, String> map) {
        // 用 setResut()
        // 准备好要回传的数据后，只要使用finish()的方法就能把打包好的数据发给A且运行onActivityResult()部分的代码
        Intent intent = new Intent();
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }

        intent.putExtra(SerializableKey, serializable);

		/* 将数据打包到aintent Bundle 的过程略 */
        ((Activity) (context)).setResult(Return_zhi, intent);// 这理有2个参数(int
        // resultCode,
        // Intent
        // intent)
        ((Activity) (context)).finish();
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left2, R.anim.slide_right2);
    }

    /**
     * startActivityForResult 回传值
     *
     * @param context
     * @param Return_zhi   回传值
     * @param serializable 需要回传的序列化对象数据
     */
    public static void jumpResultfinish(Context context, int Return_zhi, Serializable serializable) {
        // 用 setResut()
        // 准备好要回传的数据后，只要使用finish()的方法就能把打包好的数据发给A且运行onActivityResult()部分的代码
        Intent intent = new Intent();

        intent.putExtra(SerializableKey, serializable);
        /* 将数据打包到aintent Bundle 的过程略 */
        ((Activity) (context)).setResult(Return_zhi, intent);// 这理有2个参数(int
        // resultCode,
        // Intent
        // intent)
        ((Activity) (context)).finish();
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left2, R.anim.slide_right2);
    }

    /**
     * startActivityForResult 回传值
     *
     * @param context
     * @param Return_zhi 回传值
     * @param map        需要回传的数据
     */
    public static void jumpResultfinish(Context context, int Return_zhi, HashMap<String, String> map, boolean isOpenAnima) {
        // 用 setResut()
        // 准备好要回传的数据后，只要使用finish()的方法就能把打包好的数据发给A且运行onActivityResult()部分的代码
        Intent intent = new Intent();
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                intent.putExtra(entry.getKey(), entry.getValue());
                System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());
            }
        }
        /* 将数据打包到aintent Bundle 的过程略 */
        ((Activity) (context)).setResult(Return_zhi, intent);// 这理有2个参数(int
        // resultCode,
        // Intent
        // intent)
        ((Activity) (context)).finish();
//		if (isOpenAnima)
//			((Activity) (context)).overridePendingTransition(R.anim.slide_left2, R.anim.slide_right2);
    }

    public static void jumpto(Context context, Class<?> classs, ArrayList<String> list, String key) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(context, classs);
        intent.putStringArrayListExtra(key, list);
        ((Activity) (context)).startActivity(intent);
//		((Activity) (context)).overridePendingTransition(R.anim.slide_left, R.anim.slide_right);

    }

    /**
     * 跳转到网络设置页面
     *
     * @param context
     */
    public static void jumptoNetSetting(Context context) {
        // TODO Auto-generated method stub
        Intent intent = new Intent("android.settings.WIRELESS_SETTINGS");
        ((Activity) (context)).startActivity(intent);

    }

    /**
     * 跳转到设置页面
     *
     * @param context
     */
    public static void jumptoSetting(Context context) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(Settings.ACTION_SETTINGS);
        ((Activity) (context)).startActivity(intent);

    }


    /**
     * 跳转到微信
     *
     * @param context
     */
    public static void jumptoWeChat(Context context) {
        try {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");

            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setComponent(cmp);
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(context, "检查到您手机没有安装微信，请安装后使用该功能", Toast.LENGTH_LONG).show();
        }
    }

    /**
     * 跳转到QQ个人
     * http://blog.csdn.net/gongzhuo1987/article/details/50561343
     *
     * @param context
     */
    public static void jumptoQQ_person(Context context, String qqnumber) {
        String url11 = "mqqwpa://im/chat?chat_type=wpa&uin=" + qqnumber + "&version=1";
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url11)));
    }

    /**
     * 跳转到QQ群
     * http://blog.csdn.net/gongzhuo1987/article/details/50561343
     *
     * @param context
     */
    public static void jumptoQQ_Group(Context context, String qqgroupnumber) {
        String url11 = "mqqwpa://im/chat?chat_type=group&uin=+" + qqgroupnumber + "&version=1";
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url11)));
    }

    /**
     * 跳转到一个网页
     * http://blog.csdn.net/gongzhuo1987/article/details/50561343
     *
     * @param context
     */
    public static void jumptoUrl(Context context, String url) {
        Uri uri = Uri.parse(url);
        Intent it = new Intent(Intent.ACTION_VIEW, uri);
        context.startActivity(it);
    }
}
